package weaver.interfaces.cese.duss.action.fee;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.cese.duss.ceseutil.ReserveUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-10-31
 * @Description: 备用金归还
 * @ModifyLog:
 **/
public class WeaReserveReturnAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        RecordSet rs = new RecordSet();
        writeLog( "----WeaReserveReturnAction-------" + requestid );
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
       // double yfsjes = 0.00;
        try {
            String sql = "select byjlx,byjzrr,xmbm,ghje from " + tablename + " where requestid=?";
            writeLog( sql, requestid );
            rs.executeQuery( sql, requestid );
            rs.next();
            String byjlx = Util.null2String( rs.getString( "byjlx" ) );//备用金类型  1-项目/0-个人
            String byjzrr = Util.null2String( rs.getString( "byjzrr" ) );//备用金责任人
            String xmbm = Util.null2String( rs.getString( "xmbm" ) );//项目编码
            //还款金额=(费用报销+差旅报销)冲抵+备用金归还更新
            if ("0".equals( byjlx )) {//个人
                double yfsjes = ReserveUtil.calReserveBorrow(byjlx,xmbm,byjzrr);
                String sql1 = "update uf_byjglr set yfsje=? where byjlx=? and byjzrr=?";
                rs.executeUpdate(sql1,new Object[]{yfsjes,byjlx,byjzrr});
                rs.writeLog(sql1,String.join(",",yfsjes+"",byjlx,byjzrr));
            } else {//项目
                double yfsjes = ReserveUtil.calReserveBorrow(byjlx,xmbm,byjzrr);
                String sql1 = "update uf_byjglr set yfsje=? where byjlx=? and xmbm=?";
                rs.executeUpdate(sql1,new Object[]{yfsjes,byjlx,xmbm});
                rs.writeLog(sql1,String.join(",",yfsjes+"",byjlx,xmbm));
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }



}
